home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
CMP.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
6KB
|
237 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 012290 : Initial
*/
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
#define BUFSIZE 256
/*******************************************************************
*
* Function CMP
*
* cmp [options] file1 file2
*
* cmp compares two files. If file1 is '-' then the standard input is used.
* If the files are the same cmp does nothing. If they differ the byte offset
* and differing bytes are printed.
*
* options
* -l print the byte offset and the bytes for each difference.
* -s print nothing for differing files, output return code only.
*
*******************************************************************/
#define cmpLong (**MyShell).Proc[ProcID].bflags.f0
#define cmpSilent (**MyShell).Proc[ProcID].bflags.f1
#define cmpAbort (**MyShell).Proc[ProcID].bflags.f2
void CMPFile( WHandle ShellWh, int ProcID, char *file1, char *file2 )
{
int16 aRefNum, bRefNum,
aErr, bErr,
aLineNum, bLineNum,
filesCmp = TRUE,
cantCmp = TRUE,
diffFound = FALSE;
char aBuf[ BUFSIZE ],
bBuf[ BUFSIZE ];
int32 offset = 0;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
aRefNum = OpenFileDirect( file1, 'TEXT', fsRdPerm );
if( aRefNum )
{
bRefNum = OpenFileDirect( file2, 'TEXT', fsRdPerm );
if( bRefNum )
{
aLineNum = 1; bLineNum = 1;
cantCmp = FALSE;
while( filesCmp && !cmpAbort )
{
if( UserAbort() )
cmpAbort = TRUE;
aErr = ReadLine( aRefNum, aBuf, BUFSIZE );
bErr = ReadLine( bRefNum, bBuf, BUFSIZE );
if( aErr || bErr )
break;
if( strcmp( aBuf, bBuf ) ) /* did not compare */
{
if( !cmpSilent )
procPrintf( ShellWh, ProcID, "Mismatch line %d\n%s%s",
aLineNum, aBuf, bBuf );
filesCmp = cmpLong;
diffFound = TRUE;
}
offset += (int32) strlen( aBuf );
aLineNum++;
bLineNum++;
}
FSClose( aRefNum );
FSClose( bRefNum );
}
else
FSClose( aRefNum );
}
if( cantCmp )
procPrintf( ShellWh, ProcID, "cmp : can't compare %s and %s\n",
file1, file2 );
else
if( cmpSilent )
procPrintf( ShellWh, ProcID, "%d\n", diffFound );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoCMP( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
int16 i, argc;
char *cp, arg1[ 256 ], arg2[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
cmpAbort = TRUE;
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
cmpAbort = FALSE;
cmpLong = FALSE;
cmpSilent = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, arg1 );
cp = arg1;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'l' : /* long list of compare */
cmpLong = TRUE;
break;
case 's' : /* silent mode */
cmpSilent = TRUE;
break;
}
}
*arg1 = '\0';
*arg2 = '\0';
for( i = 1; i < argc; i++ )
{
if( *arg1 == '\0' )
{
GetArgv( ShellWh, ProcID, i, arg1 );
if( *arg1 == '-' )
*arg1 = '\0';
}
else if( *arg2 == '\0' )
{
GetArgv( ShellWh, ProcID, i, arg2 );
if( *arg2== '-' )
*arg2 = '\0';
else
break;
}
}
if( *arg1 && *arg2 )
CMPFile( ShellWh, ProcID, arg1, arg2 );
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}